//
//  FindLoveVC.m
//  Bread-Live
//
//  Created by wy on 2017/3/11.
//  Copyright © 2017年 Chris. All rights reserved.
//

#import "FindLoveVC.h"
#import "LiverMsgVC.h"
#import "LiveTimeView.h"
#import "HotLiveView.h"
#import "HotLiveTableViewCell.h"
#import "HotLiveModel.h"
#import "TitleView.h"
#import "HotLiverModel.h"
#import "HotLiverTableViewCell.h"
#import "NoMoreMsgView.h"


static NSString *hotCELL = @"HOTCELL";
static NSString *liverCELL = @"LIVERCELL";

@interface FindLoveVC ()<UITableViewDelegate,UITableViewDataSource>

@property(nonatomic,strong) UITableView *wTableView;
@property(nonatomic,strong) NoMoreMsgView *footView;
@property(nonatomic,strong) NSMutableArray *liverData;
@property(nonatomic,strong) NSMutableArray *hotLiveData;

@end

@implementation FindLoveVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self hotLive];
    [self hotLiver];
    
    [self.wTableView reloadData];
    
}

-(void)hotLiver{
    
    self.liverData = [NSMutableArray array];
    NSDictionary *dic =@{
                         @"isfollow":@YES,
                         @"name":@"吴德强",
                         @"headImgUrl":@"http://images.mianbaolive.com/manage/7932d776-2ea2-44fa-ae01-799505df5b37.jpg",
                         @"time":@"10天后·直播·START",
                         @"descritionText":@"",
                         };
    HotLiverModel *mod  = [[HotLiverModel alloc] init];
    
    [mod setValuesForKeysWithDictionary:dic];
    
    NSDictionary *dic1 =@{
                         @"isfollow":@NO,
                         @"name":@"小碗",
                         @"headImgUrl":@"http://images.mianbaolive.com/manage/1ca64b47-db26-471c-9eaf-7fa8b10bd8d3.jpg",
                         @"time":@"10天后·直播·START",
                         @"descritionText":@"",
                         };
    HotLiverModel *mod1  = [[HotLiverModel alloc] init];
    
    [mod1 setValuesForKeysWithDictionary:dic1];

    NSDictionary *dic2 =@{
                         @"isfollow":@YES,
                         @"name":@"陈大可",
                         @"headImgUrl":@"http://images.mianbaolive.com/manage/895d4d9e-cb67-4c55-b4af-8ab29112fa2a.jpg",
                         @"time":@"8天前·直播·END",
                         @"descritionText":@"本话题适用于：刚开始找工作的大学毕业生，工作超过四年但是缺乏跳槽经验的职场人士，职场经验丰富但是简历缺乏亮点的职场人士。课程中间有有奖问答，欢迎来听。",
                         };
    HotLiverModel *mod2  = [[HotLiverModel alloc] init];
    
    [mod2 setValuesForKeysWithDictionary:dic2];

    
    
    
    
    [self.liverData addObject:mod];
    [self.liverData addObject:mod1];
    [self.liverData addObject:mod2];
}

-(void)hotLive{
    self.hotLiveData = [NSMutableArray array];
    NSDictionary *dic =@{
                         @"title":@"10天瘦7斤系列",
                         @"type":@"健身",
                         @"bgUrl":@"http://images.mianbaolive.com/manage/f0cddc9e-a0b8-4b85-bc82-75909a7ec8f1.png",
                         @"time":@"18天前",
                         
                         };
    HotLiveModel *mod  = [[HotLiveModel alloc] init];
    
    [mod setValuesForKeysWithDictionary:dic];
    
    NSDictionary *dic1 =@{
                          @"title":@"如何在2017年的互联网江湖快速崛起！",
                          @"type":@"职场",
                          @"bgUrl":@"http://images.mianbaolive.com/manage/aec9186e-df0f-4bfc-9d63-11fa5e7da2dc.jpg",
                          @"time":@"10小时后",
                          };
    HotLiveModel *mod1  = [[HotLiveModel alloc] init];
    
    [mod1 setValuesForKeysWithDictionary:dic1];
    
    [self.hotLiveData addObject:mod];
    [self.hotLiveData addObject:mod1];
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (section == 0) {
        return self.liverData.count;
    }
    return self.hotLiveData.count;
    
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 2;
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 10.0;
    
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    
    NSString *title = [NSString string];
    
    title = section == 0 ?@"热门主讲人":@"热门LIVE";
    
    return [TitleView initWithTitle:title];
    
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 40;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0) {
        
       return 120;
    }
    return 170;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
    HotLiveTableViewCell *hotCell = [tableView dequeueReusableCellWithIdentifier:hotCELL];
    hotCell.selectionStyle  = UITableViewCellSelectionStyleNone;
    
    HotLiverTableViewCell *liverCell = [tableView dequeueReusableCellWithIdentifier:liverCELL];
    liverCell.selectionStyle  = UITableViewCellSelectionStyleNone;
    if (indexPath.section ==0) {
        liverCell.model = self.liverData[indexPath.row];
        
        return liverCell;
    }
    
    hotCell.model = self.hotLiveData[indexPath.row];
        
    return hotCell;
 
}

- (void)tableView:(UITableView*)tableView willDisplayCell:(UITableViewCell*)cell forRowAtIndexPath:(NSIndexPath*)indexPath{
    
    if([cell respondsToSelector:@selector(setSeparatorInset:)]){
        
        [cell setSeparatorInset:UIEdgeInsetsZero];
        
    }
    
    if([cell respondsToSelector:@selector(setLayoutMargins:)]) {
        
        [cell setLayoutMargins:UIEdgeInsetsZero];
    }
}


-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
        [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    if (indexPath.section == 0) {
        
        LiverMsgVC *vc = [[LiverMsgVC alloc] init];
        
        [self.navigationController pushViewController:vc animated:NO];
    }
    
}


-(UITableView *)wTableView{
    if (!_wTableView) {
        _wTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0,kWidth , kHeight-64) style:UITableViewStyleGrouped];
        _wTableView.delegate = self;
        _wTableView.dataSource = self;
        _wTableView.tableFooterView = self.footView;
        
        [_wTableView registerClass:[HotLiveTableViewCell class] forCellReuseIdentifier:hotCELL];
        [_wTableView registerClass:[HotLiverTableViewCell class] forCellReuseIdentifier:liverCELL];
        
        [self.view addSubview:_wTableView];
    }
    return _wTableView;
}


-(NoMoreMsgView *)footView{
    if (!_footView) {
        _footView = [[NoMoreMsgView alloc] initWithFrame:CGRectMake(0, 0, kWidth, 80)];
        
    }
    return _footView;
}








/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/


@end
